<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 平均等待时间 -->
    <script>
      var averageWaitingTime = function (customers) {
        let time = 0 //当前时间
        let timenum = 0 //所有顾客等待总时间
        let man = customers.length //顾客人数
        for (let i = 0; i < man; ++i) {
          if (time <= customers[i][0]) {
            time = customers[i][0] //在顾客到来之前，或者顾客刚好到了，则time等于顾客到的时间(开始做菜)
            timenum += customers[i][1] //customers[i][1]则为当前顾客的等待时间
          } else {
            //当前时间顾客还没到
            timenum += time - customers[i][0] + customers[i][1]
          }
          time += customers[i][1]
        }
        return timenum / man
      }
      console.log(
        averageWaitingTime([
          [1, 2],
          [2, 5],
          [4, 3]
        ])
      )
    </script>
  </body>
</html>
